package org.davidliebman.android.awesomewifi;

import java.util.ArrayList;
import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiManager;
import android.util.Log;
import android.widget.Toast;

public class WiFiScanReceiver extends BroadcastReceiver {
  private static final String TAG = "WiFiScanReceiver";
  Wifi wifiDemo;
    
  public WiFiScanReceiver(Wifi wifiDemo) {
    super();
    this.wifiDemo = wifiDemo;
  }

  @Override
  public void onReceive(Context c, Intent intent) {

	boolean mJustConnected = false;
	
    String mExtraWifiState = intent.getAction();
    if (mExtraWifiState.contentEquals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
    	NetworkInfo mInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    	mJustConnected = mInfo.isConnected();
    }
        
    
    wifiDemo.mCanSelect = true;
    
//    if (wifiDemo.mShouldLogin &&
//    		wifiDemo.wifi.getConnectionInfo().getSSID() != null &&
//    		(mJustConnected || wifiDemo.mAlreadyConnected // || wifiDemo.mDebug // test if State info fails... 
//    		) &&
//    		wifiDemo.wifi.getConnectionInfo().getSSID().contains(Wifi.NP_SPECS_SSID)) {
//    	wifiDemo.mHandler.sendEmptyMessage(Wifi.DIALOG_SCAN_NP_ID);
//    	return;
//    }
    
    
    wifiDemo.mHandler.sendEmptyMessage(Wifi.DIALOG_DONOTHING_ID);
    //Log.d(TAG, "onReceive() message: " + message);
  }

}
